package com.itheima.app.controller;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.app.manager.VideoManager;
import com.itheima.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class VideoController {

    @Autowired
    VideoManager videoManager;

    //推荐视频列表
    @GetMapping("/smallVideos")
    public ResponseEntity findRecommendVideoByPage(
            @RequestParam(value = "page",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize){
        PageBeanVo pageBeanVo = videoManager.findRecommendVideoByPage(UserHolder.get().getId(),pageNum,pageSize);
        return ResponseEntity.ok(pageBeanVo);
    }

    //发布视频
    @PostMapping("/smallVideos")
    public void save(MultipartFile videoThumbnail,MultipartFile videoFile) throws IOException {
        //1.接受两个文件
        //2.获取登陆者id
        //3.调用manager完成保存操作
        videoManager.save(UserHolder.get().getId(),videoThumbnail,videoFile);
    }

    //关注用户
    @PostMapping("/smallVideos/{focusUserId}/userFocus")
    public void focusUser(@PathVariable Long focusUserId){
        //1.获取路径参数和登陆者id
        //2.调用manager完成关注操作
        videoManager.focusUser(UserHolder.get().getId(),focusUserId);
    }

    //取消关注用户
    @PostMapping("/smallVideos/{focusUserId}/userUnFocus")
    public void unFocusUser(@PathVariable Long focusUserId){
        //1.获取路径参数和登陆者id
        //2.调用manager完成取消关注操作
        videoManager.unFocusUser(UserHolder.get().getId(),focusUserId);
    }
}
